package com.example.demo.job;

import com.example.demo.service.Impl.MessageServiceImpl;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.Method;

public class CrawlerJob implements Job {

    @Autowired
    private MessageServiceImpl messageService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        String taskName = context.getJobDetail().getKey().getName();
        try {
            // 根据任务名称调用相应的爬虫方法
            Method method = messageService.getClass().getMethod(taskName);
            method.invoke(messageService);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
